package com.ikun.service.impl;

import com.ikun.mapper.TbUserMapper;
import com.ikun.pojo.TbUser;
import com.ikun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    TbUserMapper userMapper;

    //查询好人榜的方法
    @Override
    public List<TbUser> selGoodman(int date) {
        List<TbUser> tbUserList = userMapper.selGoodman(date);
        return tbUserList;
    }

    @Override
    public List<TbUser> showusers() {
        List<TbUser>  list=userMapper.showusers();
        return  list;
    }

    @Override
    public int deluser(int id) {
        int count=userMapper.deluser(id);
        if (count>0){
            return count;
        }
        else {
            return 0;
        }
    }

    //修改用户头像
    @Override
    public int updateMyPic(Long userid, String url) {
        int count = userMapper.updateMyPic(userid,url);
        return count;
    }

    //修改用户密码
    @Override
    public int updateMyPwd(Long userid, String oldPwd, String newPwd) {
        int count = userMapper.updateMyPwd(userid,oldPwd,newPwd);
        return count;
    }


    @Override
    public int updateMyInfo(TbUser tbUser) {
        int count = userMapper.updateMyInfo(tbUser);
        return count;
    }

    //扣钱
    @Override
    public int deductMoney(Long userID, BigDecimal money) {
        int count = userMapper.deductMoney(userID,money);
        return count;
    }

    @Override
    public TbUser getUser(String account, String pwd) {
        System.out.println(account+pwd);
       TbUser tbUser =  userMapper.getUser(account,pwd);
        return tbUser;
    }

    @Override
    public int registerUser(String nickname, String account, String pwd, String email, String sex) {
        return userMapper.registerUser(nickname,account,pwd,email,sex);
    }
//修改用户信息
    @Override
    public int updatemsg(int id, String nickname, String realname, String pwd, String sex, String email, String phone, String department, String profession, String classes) {
        int count=userMapper.updatemsg(id,nickname,realname,pwd,sex,email,phone,department,profession,classes);
        return  count;
    }

}
